void main() {
  basicTest();
  strTest();
  fun1();
  selectFunction('zhangsan');
  selectFunction('lisi', type: 1);
  selectFunction('wangwu', type: 2, money: 2.2);
}

//基本学习
void basicTest() {
  String str = "测试";
  int a = 10;
  double b = 20.2;
  bool bl = true;
//num是数值类型
  num d = 20;
  print("a = $a");
  print("d = $d");
  print("str = $str");

  var dd = 10;
  print("dd = $dd");
  dd = 20;
  print("dd = $dd");

  dynamic aa = "NBA";
  print("aa = $aa");
  aa = 824;
  print("aa = $aa");

  var fullName = '';
  assert(fullName.isEmpty); //内容为真就继续执行
  print("fullName = $fullName");

  var c = 5;
  var f = 5;
  print(c / f); //输出结果：2.5
  print(c ~/ f); //输出结果：2
  print(c == f);
  if (c is String) {
    print('String');
  }
  // (c as String).isNotEmpty;

  String value = "222";
  var v1 = "";
  dynamic v2;
  print('v2 = $v2');
  v1 = value;
  v2 ??= v1; //如果v2是空的话,就重新赋值
  //条件表达式：?? 判断是否为空，为空执行??后面的内容
  print('v2 = $v2');
}

void strTest() {
  String s1 = "First string.....";
  String s2 = "   Second string" " ddd";
  print(s1 + s2); // First string.....   Second stringddd
  // 使用换行符以及空格
  String str2 = '单引号符串'
      '换行了'
      '再加空格'
      '拼接';
  print("str2:$str2"); // 输出结果：单引号符串换行了再加空格拼接
  // 单双引号 空格拼接
  String str3 = "单双引号空格字符串" '拼接' "~";
  print("str3:$str3"); // 输出结果：单双引号字符串空格拼接~
  // 单双引号 换行符以及空格
  String str4 = "单双引号符串\n"
      '换行了'
      '再加空格'
      '拼接';
  print("str4:$str4");
  // 输出结果：单双引号符串
  //换行了再加空格拼接

  StringBuffer stringBuffer = StringBuffer();
  for(int i = 0; i < 10;i++) {
    stringBuffer.write(i);
  }
  stringBuffer
    ..write("1")
    ..write("2")
    ..write("new")
    ..write('\n');
  print(stringBuffer);
}

fun1() => print('无参数函数');

anonFunc(name, type) => 'I am $name 类型：$type';

void selectFunction(String name, {int? type, double? money}) {
  print("名字：$name--类型：$type--金额：$money");
}
